package com.example.yls.demoa;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobSMS;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.listener.QueryListener;
import cn.bmob.v3.listener.SaveListener;

public class PhoneActivity extends AppCompatActivity {
    private EditText edtPhone;
    private EditText edtCode;
    private Button btnGetCode;
    private Button btnRelog;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone);
        edtPhone= findViewById(R.id.edt_phone);
        edtCode= findViewById(R.id.edt_code);
        btnGetCode =findViewById(R.id.btn_getcode);
        final String phone = edtPhone.getText().toString();
        btnGetCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                BmobSMS.requestSMSCode(phone, "dengluyanzhengma", new QueryListener<Integer>() {
                    @Override
                    public void done(Integer integer, BmobException e) {
                        if(e==null){
                            Toast.makeText(PhoneActivity.this,"验证码已发送",Toast.LENGTH_SHORT).show();
                        }

                    }
                });
            }
        });
        btnRelog = findViewById(R.id.btn_reglog);
        edtCode = findViewById(R.id.edt_code);
        btnRelog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BmobUser.signOrLoginByMobilePhone(phone, "验证码", new LogInListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if(e==null){
                            Toast.makeText(PhoneActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });
    }




}
